package cn.edu.jiangnan.cashmanagement.service.department;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import cn.edu.jiangnan.cashmanagement.entity.DepartmentEntity;

@Repository
public class DepartmentDaoImpl implements DepartmentDao {
	
	@Inject
	HibernateTemplate hibernateTemplate;

	@Override
	public Long addDepartment(DepartmentEntity department) {
		return (Long)hibernateTemplate.save(department);
	}

	@Override
	public boolean deleteDepartment(List<Long> params) {
		List<DepartmentEntity> entities = new ArrayList<DepartmentEntity>(params.size());
		for(Long id:params){
			entities.add(hibernateTemplate.get(DepartmentEntity.class,id));
		}
		hibernateTemplate.deleteAll(entities);
		return true;
	}

	@Override
	public List<DepartmentEntity> findDepartmentsByCondition(
			DepartmentEntity params) {
		StringBuffer hql = new StringBuffer("from DepartmentEntity department where 1=1 ");
		return hibernateTemplate.find(hql.toString());
	}

	@Override
	public boolean updateDepartment(DepartmentEntity department) {
		hibernateTemplate.update(department);
		return true;
	}
	
	
}
